# 压缩
import os
import zipfile


def zipDir(dirpath, outpath):
    zip = zipfile.ZipFile(outpath, 'w', zipfile.ZIP_DEFLATED)
    for path, dirnames, filenames in os.walk(dirpath):
        fpath = path.replace(dirpath, '')
        if len(filenames) == 0:
            zip.write(path, fpath)
        for filename in filenames:
            zip.write(os.path.join(path, filename), os.path.join(fpath, filename))
    zip.close()


